package com.tencent.controller;

import com.tencent.entity.Member;
import com.tencent.entity.Result;
import com.tencent.service.LoginService;
import com.tencent.service.MemberYService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: Fame
 * @date: 2022-08-31 15:45
 * @description:
 */
@RestController
@RequestMapping("/memberY")
public class MemberYController {

    @Autowired(required = false)
    private MemberYService memberYService;

    @Autowired
    private LoginService loginService;

    @GetMapping
    public Result getBean(){
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        String username = (String) authentication.getPrincipal();
        Integer id = loginService.findIdByUsername(username);
        return Result.success(memberYService.getById(id));
    }

    @GetMapping("/getLevel")
    public Result getLevel(Integer id){
        return Result.success(memberYService.getLevel(id));
    }
}
